{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import shutil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for dir in ['linai', 'waiyuan', 'xianai']:\n",
    "    for pat in os.listdir(dir):\n",
    "        # 目的文件夹\n",
    "        aim_dir = os.path.join('data_ok', dir, pat)\n",
    "        if not os.path.exists(aim_dir):\n",
    "            os.makedirs(aim_dir)\n",
    "        # 遍历当前病人所有dcm\n",
    "        for root, f_dir, files in os.walk(os.path.join(dir, pat)):\n",
    "            for file in files:\n",
    "                if file.endswith('.dcm'):\n",
    "                    print(root)\n",
    "                    print(file)\n",
    "                    old = os.path.join(root, file)\n",
    "                    new = os.path.join(aim_dir, file)\n",
    "                    shutil.move(old, new)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list(os.walk(os.path.join('linai', 'BU FAN YING')))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
